# @Author ZhangGJ
# @Date 2021/11/22 17:52

import numpy as np


def array():
    n1 = np.array([1, 2, 3])
    n2 = np.array([0.1, 0.2, 0.3])
    n3 = np.array([[1, 2], [2, 3]])

    list = [1, 2, 3]
    n4 = np.array(list, dtype=np.float_)
    n5 = np.array(list, dtype=float)
    print(n4)
    print(n4.dtype)
    print(type(n4[0]))

    nd1 = [1, 2, 3]
    nd2 = np.array(nd1, ndmin=3)
    print(nd2)

    n = np.empty([2, 3])
    print(n)

    n = np.zeros((3, 3), np.uint8)
    print(n)

    n = np.ones((4, 4), np.uint8)
    print(n)


def random():
    n1 = np.random.randint(1, 3, 10)
    print(n1)
    n2 = np.random.randint(5, 10)
    print(n2)
    n3 = np.random.randint(5, size=(2, 5))
    print(n3)


def operate_array():
    n1 = np.array([1, 2])
    n2 = np.array([3, 4])
    print(n1 + n2)
    print(n1 - n2)
    print(n1 * n2)
    print(n1 / n2)
    print(n1 ** n2)
    print(n1 < n2)
    print(n1 > n2)
    print(n1 == n2)
    print(n1 != n2)

    n1 = np.array([1, 2])
    n2 = n1.copy()
    print(n1 == n2)
    n2[0] = 9
    print(n1)
    print(n2)
    print(n1 == n2)


def array_index():
    n1 = np.array([1, 2, 3])
    print(n1[0])
    print(n1[1])
    print(n1[0:2])
    print(n1[1:])
    print(n1[:2])

    n = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    print(n)
    print(n[:3])
    print(n[3:6])
    print(n[6:])
    print(n[::])
    print(n[:])
    print(n[::2])
    print(n[1::5])
    print(n[2::6])

    print(n[::-1])
    print(n[:-3:-1])
    print(n[-3:-5:-1])
    print(n[-5::-1])


def two_array():
    n = np.array([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]])
    print(n[1])
    print(n[1, 2])
    print(n[-1])

    n = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    print(n[:2, 1:])
    print(n[1, :2])
    print(n[:2, 2])
    print(n[:, :1])


if __name__ == '__main__':
    array_index()
    two_array()
